﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class HomePage_Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            rptGgtzBind();
            rptCzbzBind();
            rptZcfgBind();
            rptJggsBind();
            rptCgdtBind();
            rptZxfbBind();
            rptQaBind();
            Picturenews_id();
        }
    }
    //图片新闻id
    public string Picturenews_id()
    {
        HZ.MBSM.DBUtility.Db db = new HZ.MBSM.DBUtility.Db();
        string _strSql = "select top 4 news_id,news_title,DownLoad from dbo.newsPicture where IsShow =0 order by news_id desc ";
        System.Data.IDataReader dr = db.DataReader(_strSql);
        string _strid = "", _strtitle = "", _strDown = "";
        while (dr.Read())
        {

            _strid += "ContentShow.aspx?pid=" + MsgBox.JiaMiobj_Encrypt(dr["news_id"].ToString()) + "|";

            if (dr["news_title"].ToString().Length > 18)
            {
                _strtitle += dr["news_title"].ToString().Remove(18) + "...|";
            }
            else
            {
                _strtitle += dr["news_title"].ToString() + "|";
            }
            _strDown += "../uploadfile/" + dr["DownLoad"].ToString() + "|";

        }

        dr.Close();
        dr.Dispose();
        db.Close();
        if (_strid == "")
        {
            return "aa";
        }
        else
        {
            return _strid = _strid.Remove(_strid.Length - 1) + "∏" + _strDown.Remove(_strDown.Length - 1) + "∏" + _strtitle.Remove(_strtitle.Length - 1);
        }
    }

    /// <summary>
    /// 公告通知数据绑定
    /// </summary>
    private void rptGgtzBind()
    {
        HZ.MBSM.DBUtility.Db db = new HZ.MBSM.DBUtility.Db();

        string strSql = "select top 7 Notid,Title,AddDate,'' as img from Note order by Notid desc ";
        DataTable dt = db.DataTable(strSql);

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (System.DateTime.Now <= Convert.ToDateTime(dt.Rows[i]["AddDate"].ToString()).AddDays(2))
                {
                    dt.Rows[i]["img"] = "&nbsp;<img src='../images/new.gif' width='30' height='10'>";
                }
            }

            rptGgtz.Visible = true;

            rptGgtz.DataSource = dt;
            rptGgtz.DataBind();
        }
        else
        {
            rptGgtz.Visible = false;
        }
        dt.Dispose();
        db.Close();
    }

    /// <summary>
    /// 操作帮助数据绑定
    /// </summary>
    private void rptCzbzBind()
    {
        HZ.MBSM.DBUtility.Db db = new HZ.MBSM.DBUtility.Db();

        string strSql = "select top 7 Id,Title,AddDate,'' as img from HelpTable  order by  id desc ";
        DataTable dt = db.DataTable(strSql);

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (System.DateTime.Now <= Convert.ToDateTime(dt.Rows[i]["AddDate"].ToString()).AddDays(2))
                {
                    dt.Rows[i]["img"] = "&nbsp;<img src='../images/new.gif' width='30' height='10'>";
                }
            }

            rptCzbz.Visible = true;

            rptCzbz.DataSource = dt;
            rptCzbz.DataBind();
        }
        else
        {
            rptCzbz.Visible = false;
        }

        dt.Dispose();
        db.Close();
    }

    /// <summary>
    /// 政策法规数据绑定
    /// </summary>
    private void rptZcfgBind()
    {
        HZ.MBSM.DBUtility.Db db = new HZ.MBSM.DBUtility.Db();

        string strSql = "select top 6 LawId,Title,AddDate,'' as img from Law  order by  LawId desc ";
        DataTable dt = db.DataTable(strSql);

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (System.DateTime.Now <= Convert.ToDateTime(dt.Rows[i]["AddDate"].ToString()).AddDays(2))
                {
                    dt.Rows[i]["img"] = "&nbsp;<img src='../images/new.gif' width='30' height='10'>";
                }
            }

            rptZcfg.Visible = true;

            rptZcfg.DataSource = dt;
            rptZcfg.DataBind();
        }
        else
        {
            rptZcfg.Visible = false;
        }

        dt.Dispose();
        db.Close();
    }

    /// <summary>
    /// 结果公示数据绑定
    /// </summary>
    private void rptJggsBind()
    {
        HZ.MBSM.DBUtility.Db db = new HZ.MBSM.DBUtility.Db();

        string strSql = "select top 6 ID,ShowName,ShowProject,ShowSort,ShowUrl,ShowDate,'' as img from Show order by  ShowDate desc ";
        DataTable dt = db.DataTable(strSql);

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (System.DateTime.Now <= Convert.ToDateTime(dt.Rows[i]["ShowDate"].ToString()).AddDays(2))
                {
                    dt.Rows[i]["img"] = "&nbsp;<img src='../images/new.gif' width='30' height='10'>";
                }
            }

            rptJggs.Visible = true;

            rptJggs.DataSource = dt;
            rptJggs.DataBind();
        }
        else
        {
            rptJggs.Visible = false;
        }

        dt.Dispose();
        db.Close();
    }

    /// <summary>
    /// 采购动态数据绑定
    /// </summary>
    private void rptCgdtBind()
    {
        HZ.MBSM.DBUtility.Db db = new HZ.MBSM.DBUtility.Db();

        string strSql = "select top 6 TrendID,Title,AddDate,'' as img from GoodsTrend order by  TrendID desc ";
        DataTable dt = db.DataTable(strSql);

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (System.DateTime.Now <= Convert.ToDateTime(dt.Rows[i]["AddDate"].ToString()).AddDays(2))
                {
                    dt.Rows[i]["img"] = "&nbsp;<img src='../images/new.gif' width='30' height='10'>";
                }
            }

            rptCgdt.Visible = true;

            rptCgdt.DataSource = dt;
            rptCgdt.DataBind();
        }
        else
        {
            rptCgdt.Visible = false;
        }

        dt.Dispose();
        db.Close();
    }

    /// <summary>
    /// 问题反馈数据绑定
    /// </summary>
    private void rptQaBind()
    {
        HZ.MBSM.DBUtility.Db db = new HZ.MBSM.DBUtility.Db();

        string strSql = "select top 12 id,title,createdate,'' as img from board  order by  id desc ";
        DataTable dt = db.DataTable(strSql);

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (System.DateTime.Now <= Convert.ToDateTime(dt.Rows[i]["createdate"].ToString()).AddDays(2))
                {
                    dt.Rows[i]["img"] = "&nbsp;<img src='../images/new.gif' width='30' height='10'>";
                }
            }

            rptQa.Visible = true;

            rptQa.DataSource = dt;
            rptQa.DataBind();
        }
        else
        {
            rptQa.Visible = false;
        }

        dt.Dispose();
        db.Close();
    }

    /// <summary>
    /// 最新发布数据绑定
    /// </summary>
    private void rptZxfbBind()
    {
        HZ.MBSM.DBUtility.Db db = new HZ.MBSM.DBUtility.Db();
        string strSql = @"select top 6 *,'' as img from (
                            select top 6 'ContentShow.aspx' as ShowUrl, Notid as id,Title,AddDate,'ggtz' as type from Note order by AddDate desc
                            union
                            select top 6 'ContentShow.aspx' as ShowUrl, Id,Title,AddDate,'czbz' as type from HelpTable order by AddDate desc
                            union
                            select top 6 'ContentShow.aspx' as ShowUrl, LawId as id,Title,AddDate,'zcfg' as type from Law order by AddDate desc  
                            union
                            select top 6 ShowUrl, ShowProject as id,ShowName as title,ShowDate as adddate,'jggs' as type from Show order by AddDate desc 
                            union
                            select top 6 'ContentShow.aspx' as ShowUrl, TrendID as id,Title,AddDate,'cgdt' as type from GoodsTrend order by AddDate desc 
                            ) as AA order by adddate desc";

        DataTable dt = db.DataTable(strSql);

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (System.DateTime.Now <= Convert.ToDateTime(dt.Rows[i]["AddDate"].ToString()).AddDays(2))
                {
                    dt.Rows[i]["img"] = "&nbsp;<img src='../images/new.gif' width='30' height='10'>";
                }
            }

            rptZxfb.Visible = true;

            rptZxfb.DataSource = dt;
            rptZxfb.DataBind();
        }
        else
        {
            rptZxfb.Visible = false;
        }

        dt.Dispose();
        db.Close();
        
    }

    #region
    /// <summary>
    /// 截取标题方法
    /// </summary>
    /// <param name="title"></param>
    /// <returns></returns>
    public string getTitle(object title)
    {
        if (title.ToString().Length > 10)
        {
            title = title.ToString().Remove(10) + "...";
        }
        return title.ToString();
    }
    public string getTitle2(object title)
    {
        if (title.ToString().Length > 11)
        {
            title = title.ToString().Remove(11) + "...";
        }
        return title.ToString();
    }
    public string getTitle3(object title)
    {
        if (title.ToString().Length > 8)
        {
            title = title.ToString().Remove(8) + "...";
        }
        return title.ToString();
    }

    /// <summary>
    /// 加密页面传值id方法
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public string getId(object id)
    {
        return MsgBox.JiaMiobj_Encrypt(id.ToString());
    }
    #endregion

}
